package com.jmes.web.service;

import com.jmes.web.dao.DaoManager;
import com.jmes.web.dao.UserMapper;
import com.jmes.web.model.User;
import com.jmes.web.model.UserExample;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * 用户信息管理类
 * User: jinshunlong
 * Date: 13-4-13
 * Time: 下午10:17
 */
public class UserService {
    private static Logger logger = Logger.getLogger(UserService.class);

    public static User getUserByName(final String name){
        User user = (User)DaoManager.execDao(new DaoManager.ExecDAO() {
            @Override
            public Object execDao(SqlSession sqlSession) {
                UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
                UserExample userExample = new UserExample();
                userExample.createCriteria().andNameEqualTo(name);
                List<User> userList = userMapper.selectByExample(userExample);
                if(userList == null || userList.size() == 0){
                    return null;
                }
                return userList.get(0);
            }
        });
        return user;
    }
}
